import 'dart:io';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

/// 点击高亮的 Container[不支持设置margin]
class DDContainer extends StatelessWidget {
  final GestureTapCallback? onTap;
  final GestureDoubleTapCallback? onDoubleTap;
  final GestureLongPressCallback? onLongPress;
  final Color? hightlightColor;
  final Color? splashColor;
  final radius;

  // container 属性
  final AlignmentGeometry? alignment;
  final EdgeInsetsGeometry? padding;
  final Color? color;
  final BoxDecoration? decoration;
  final Decoration? foregroundDecoration;
  final double? width;
  final double? height;
  final BoxConstraints? constraints;
  final Matrix4? transform;
  final AlignmentGeometry? transformAlignment;
  final Widget? child;
  final Clip clipBehavior;

  DDContainer({
    this.onTap,
    this.onDoubleTap,
    this.onLongPress,
    this.hightlightColor,
    this.splashColor,
    this.radius,
    Key? key,
    this.alignment,
    this.padding,
    this.color,
    this.decoration,
    this.foregroundDecoration,
    this.width,
    this.height,
    this.constraints,
    this.transform,
    this.child,
    this.clipBehavior = Clip.none,
    this.transformAlignment,
  }) : super(
          key: key,
        );

  @override
  Widget build(BuildContext context) {
    if (onTap == null && onDoubleTap == null && onLongPress == null) {
      return Container(
        alignment: alignment,
        padding: padding,
        color: color,
        decoration: decoration,
        foregroundDecoration: foregroundDecoration,
        width: width,
        height: height,
        constraints: constraints,
        transform: transform,
        transformAlignment: transformAlignment,
        child: child,
        clipBehavior: clipBehavior,
      );
    }
    if (decoration == null) {
      return Ink(
        color: color,
        width: width,
        height: height,
        child: InkWell(
          radius: (Platform.isIOS || Platform.isMacOS) ? 0.0 : radius,
          child: Container(
            child: child,
            alignment: alignment,
            padding: padding,
            // color: color,     // 这里注意不能指定color，color需要在Ink里指定
            foregroundDecoration: foregroundDecoration,
            constraints: constraints,
            transform: transform,
            transformAlignment: transformAlignment,
            clipBehavior: clipBehavior,
          ),
          onTap: onTap,
          onDoubleTap: onDoubleTap,
          onLongPress: onLongPress,
          highlightColor: hightlightColor,
          splashColor: splashColor,
        ),
      );
    }
    return Ink(
      width: width,
      height: height,
      decoration: decoration,
      child: InkWell(
        borderRadius: decoration?.borderRadius != null ? decoration!.borderRadius as BorderRadius : null,
        radius: (Platform.isIOS || Platform.isMacOS) ? 0.0 : radius,
        child: Container(
          child: child,
          alignment: alignment,
          padding: padding,
          foregroundDecoration: foregroundDecoration,
          width: width,
          height: height,
          constraints: constraints,
          transformAlignment: transformAlignment,
          transform: transform,
          clipBehavior: clipBehavior,
        ),
        onTap: onTap,
        onDoubleTap: onDoubleTap,
        onLongPress: onLongPress,
        highlightColor: hightlightColor,
        splashColor: splashColor,
      ),
    );
  }
}
